<?php
/**
 * Created by PhpStorm.
 * User: crstu
 * Date: 2016/5/31
 * Time: 23:34
 */

namespace backend\controllers;


use yii;
use backend\commands\BaseAdminController;
use common\models\DAO\User;
use common\models\DAO\UserSearch;

class UserController extends BaseAdminController
{

    public function init()
    {
        parent::init();
        $this->model = new User();
        $this->modelTitle = '会员';
    }

    
    /**
     * 用户列表
     */
    public function actionList()
    {
        $searchModel = new UserSearch();
        return $this->CommonAdvanceList(['searchModel' => $searchModel]);
    }

    
    /**
     * 添加会员
     */
    public function actionAdd(){
        return $this->CommonBaseEdit();
    }

    
    /*
     * 修改会员
     */
    public function actionEdit($id = 0){

        return $this->CommonBaseEdit(['id' => $id]);
    }

    /*
     * 修改基本资料
     */
    public function actionEditBase($id = 0){
        $options = [
            'id' => $id,
            'template' => 'edit-base',
            'scenario' => 'edit-base'
        ];
        return $this->CommonBaseEdit($options);
    }


    /*
     * 用户资料
     */
    public function actionProfile($id){
        if(!isset($id) || $id == 0){
            return $this->renderMessage('ID错误！', -1, 'danger');
        }else{
            $model =  User::findOne($id);
            if(empty($model)){
                return $this->renderMessage('ID错误！', -1, 'danger');
            }else{
                return $this->render("profile",['model' => $model]);
            }
        }
    }

}